#configure variables
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

set(VERSION_INFO "0.0.0.60")
set(TARGET_NAME "android_aec_jni")
set(Project_Bin_Dir ${PROJECT_BINARY_DIR})

project(${TARGET_NAME} VERSION ${VERSION_INFO})  
set(${CMAKE_PROJECT_NAME} ${TARGET_NAME})
message("##########0 ${Project_Bin_Dir}")

if(WIN32)
	if(Project_Bin_Dir)	
	else()
		set(Project_Bin_Dir ${PROJECT_BINARY_DIR})	
	endif()
	message("##########1 ${Project_Bin_Dir}")
	set(EXECUTABLE_OUTPUT_PATH ${Project_Bin_Dir}/lib)
	set(LIBRARY_OUTPUT_PATH ${Project_Bin_Dir}/lib)
endif()



if(MSVC)
    set(MY_VERSIONINFO_RC "${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.rc")
    configure_file("${CMAKE_CURRENT_SOURCE_DIR}/VersionInfo.rc.in" "${MY_VERSIONINFO_RC}")
else()
	set(MY_VERSIONINFO_RC "")
endif()

#set_property(GLOBAL PROPERTY USE_FOLDERS On)


#add_compile_options(-std=c++11)

add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DNOMINMAX)
#add_definitions(-DWEBRTC_USE_H264)


if(WIN32)
	set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

	add_definitions(-DWIN32_LEAN_AND_MEAN)
	add_definitions(-DWEBRTC_WIN)
	message("Windowds  .....")
else()

	message("linux .....")
	add_definitions(-DWEBRTC_POSIX)
	add_definitions(-DWEBRTC_LINUX)
	add_definitions("-Wall -g -fPIC -O3")
	
if(ANDROID)
	add_definitions(-DWEBRTC_ANDROID)
	add_definitions(-DANDROID_JNI_BUILD)
	add_definitions(-DWEBRTC_CLOCK_TYPE_REALTIME)
	add_definitions(-DWEBRTC_NS_FLOAT)
	set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -s -fPIC" )
	set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -s -fPIC" )
	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}  -Wall -s -fPIC")
	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -s -fPIC")
endif()
	
endif()

include_directories("${CMAKE_CURRENT_SOURCE_DIR}/acm_core/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/utility/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aec/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aec/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aecm/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aecm/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/agc/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/agc/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/ns/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/ns/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/system_wrappers/interface/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/system_wrappers/source/spreadsortlib/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/resampler/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/resampler/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/vad/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/vad/include/")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/vad/mock/")

set(SUB_DIR_LIST 
"./acm_core/source" 
"./acm_core/include"
"./../../webrtc/modules/audio_processing"
"./../../webrtc/system_wrappers/source"
)


if(WIN32)
list(APPEND SUB_DIR_LIST "../webrtc/rtc_base/win")
endif()


#设置子目�?

foreach(SUB_DIR ${SUB_DIR_LIST})
    #遍历源文�?
    #aux_source_directory(src/${SUB_DIR} DIR_SRCS)
	
	file(GLOB SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/*.cc")
	file(GLOB INC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/*.h")

	source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
	list(APPEND SRC_FILE_LIST ${SRC_FILES})
	list(APPEND INC_FILE_LIST ${INC_FILES})
	
	#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR})

endforeach()


list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/ns/noise_suppression.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/ns/ns_core.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aec/aec_core.cc") 
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aec/aec_rdft.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aec/aec_resampler.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aec/echo_cancellation.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aecm/aecm_core.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aecm/aecm_core_c.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/aecm/echo_control_mobile.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/agc/analog_agc.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/agc/digital_agc.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/utility/delay_estimator.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/utility/delay_estimator_wrapper.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/utility/fft4g.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/modules/audio_processing/utility/ring_buffer.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/auto_corr_to_refl_coef.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/auto_correlation.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/complex_bit_reverse.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/complex_fft.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/copy_set_operations.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/cross_correlation.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/division_operations.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/dot_product_with_scale.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/downsample_fast.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/energy.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/filter_ar.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/filter_ar_fast_q12.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/filter_ma_fast_q12.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/get_hanning_window.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/get_scaling_square.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/ilbc_specific_functions.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/levinson_durbin.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/lpc_to_refl_coef.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/min_max_operations.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/randomization_functions.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/real_fft.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/refl_coef_to_lpc.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/resample.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/resample_48khz.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/resample_by_2.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/resample_by_2_internal.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/resample_fractional.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/spl_init.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/spl_sqrt.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/spl_sqrt_floor.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/splitting_filter.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/sqrt_of_one_minus_x_squared.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/signal_processing/vector_scaling_operations.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/vad/vad_core.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/vad/vad_filterbank.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/vad/vad_gmm.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/vad/vad_sp.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/vad/webrtc_vad.c")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/resampler/push_resampler.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/resampler/push_sinc_resampler.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/resampler/resampler.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/resampler/sinc_resampler.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/vad/vad.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/audio_converter.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/audio_util.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/blocker.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/fir_filter.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/wav_file.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/wav_header.cc")
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../../webrtc/common_audio/window_generator.cc") 


list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/LibAndroidAEC/jni/android_aec.c") 
list(APPEND SRC_FILE_LIST "${CMAKE_CURRENT_SOURCE_DIR}/LibAndroidAEC/jni/android_aec_jni.cpp") 


# 生成myProject_shared动态库文件
##add_library(webrtcshare SHARED ${SRC_FILE_LIST}  ${INC_FILE_LIST})

#set(other_cpp "${CMAKE_CURRENT_SOURCE_DIR}/../../IoModule/Utility/Utility.cpp")

add_library(${TARGET_NAME} SHARED ${SRC_FILE_LIST}  ${INC_FILE_LIST} ${MY_VERSIONINFO_RC})


if(WIN32)

else()
	if(ANDROID)
	else()
		set_target_properties(${TARGET_NAME}  PROPERTIES VERSION ${VERSION_INFO} SOVERSION 1)
	endif()
endif()
#
if(ANDROID)
target_link_libraries(${TARGET_NAME} log)
#set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${CMAKE_PROJECT_NAME}")

endif()

#message("Windowds  .....webrtcshare PROJECT_BINARY_DIR " ${PROJECT_BINARY_DIR})
#message("Windowds  .....webrtcshare CMAKE_PROJECT_NAME " ${CMAKE_PROJECT_NAME})
#message("Windowds  .....webrtcshare TARGET_NAME " ${TARGET_NAME})
#message("Windowds  .....webrtcshare PROJECT_SOURCE_DIR " ${PROJECT_SOURCE_DIR})
#message("Windowds  .....webrtcshare CMAKE_CURRENT_SOURCE_DIR " ${CMAKE_CURRENT_SOURCE_DIR}) # 当前�?径cmakelist.txt 的路�?

#target_link_libraries(${TARGET_NAME}  VideoJxred)